<div class="surver">
    <h2>
        <div class="com_tit">在线调查<span>SURVEY</span></div>
    </h2>
    <?php if ($survey != null) { ?>
    <div class="surver_box">
        <script type="text/javascript">
            $(function() {
                $('#survey_result').dialog({
                    autoOpen: false,
                    width: 300,
                    height: 200,
                    buttons: {
                        "OK": function() {
                            $(this).dialog("close");
                        }
                    }
                });
            })

            function showSurveyResult() {
                $("#survey_result").dialog('open');
            }

            function voteUp() {
                $.ajax({
                    type: "POST",
                    url: "<?php echo url_for('onlineSurvey/vote') ?>",
                    data: "type=yes&surveyId=<?php echo  $survey->getOnlineSurveyId()?>"
                });
                alert("已投票");
            }

            function voteDown() {
                $.ajax({
                    type: "POST",
                    url: "<?php echo url_for('onlineSurvey/vote') ?>",
                    data: "type=no&surveyId=<?php echo  $survey->getOnlineSurveyId()?>"
                });
                alert("已投票");
            }
        </script>
        <h3>
            <?php echo $survey->getQuestion() ?>
        </h3>
        <a role='button' onclick="voteUp()">支持</a><a role='button' onclick="voteDown()">不支持</a><a role='button'
                                                                                                  onclick="showSurveyResult()">查看</a>
    </div>
    <div id="survey_result" title="调查结果">
        <?php
        $yesRatio = (float)$survey->getYesCountI() / (float)($survey->getYesCountI() + $survey->getNoCountI());
        $noRatio = (1.0 - $yesRatio);
        echo "支持比例：" . round($yesRatio * 100, 2) . "%<br>";
        echo "反对比例：" . round($noRatio * 100, 2) . "%";
        ?>
    </div>
    <?php } ?>
</div>
